#!/usr/bin/env bash

scriptsDir=$(cd "$(dirname "$0")"; pwd)
echo "scriptsDir: $scriptsDir"
chmod +x $scriptsDir/*.sh
source $scriptsDir/env.sh

cd $baseDir

service=$1

function buildJavaService() {
    echo "starting building java service"
    mvn -f $projectDir/pom.xml clean package -DskipTests
    if [  $? -ne 0 ]; then
        echo "build java service failed"
        exit 1
    fi
    cp $projectDir/target/*.jar $buildDir/
    echo "build java service success"
}

function build() {
    buildJavaService
}

function clean() {
    rm -rf $buildDir/*
}

function start() {
    java -jar $buildDir/dataflow.jar
}

if [ -z "$service" ]; then
    build
else
    case $service in
        "clean")
            clean
            ;;
        "start")
            start
            ;; 
        "buildDocker")
            clean
            build
            
            ;;        
        *)
            echo "unsupported service: $service"
            exit 1
            ;;
    esac
fi
